package com.example.base.security.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.base.security.domain.SysUserToken;
import com.example.base.security.mapper.SysUserTokenMapper;
import com.example.base.security.service.SysUserTokenService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 *
 */
@CacheConfig(cacheNames = "SysUserTokenServiceImpl")
@Service
public class SysUserTokenServiceImpl extends ServiceImpl<SysUserTokenMapper, SysUserToken>
    implements SysUserTokenService {

    @Cacheable(cacheNames = "getUserTokenByToken",key = "#token")
    @Override
    public SysUserToken getMuserTokenByToken(String token) {
        LambdaQueryWrapper<SysUserToken> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SysUserToken::getToken,token);
        SysUserToken sysUserToken=this.baseMapper.selectOne(lambdaQueryWrapper);
        return sysUserToken;
    }

    @CacheEvict(cacheNames = "getUserTokenByToken",key = "#token")
    @Override
    public SysUserToken removTokenByToken(String token) {
        LambdaQueryWrapper<SysUserToken> muserToken=new LambdaQueryWrapper<>();
        this.baseMapper.delete(muserToken);
        return null;
    }
}




